//
//  LSExamineApproveViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/21.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSExamineApproveViewController.h"
#import "LSWaitForMeToExamineTableViewCell.h"

@interface LSExamineApproveViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UIScrollView *headerSelectBottomLineView;
@property (nonatomic, strong) UIButton *waitForMeToExamineButton;
@property (nonatomic, strong) UIButton *alreadyApprovedButton;
@property (nonatomic, strong) UIScrollView *mainContentScrollView;
@property (nonatomic, strong) UITableView *waitForMeToExamineTableView;
@property (nonatomic, strong) UITableView *alreadyApprovedTableView;
@end

static NSString *LSWaitForMeToExamineTableViewCellID = @"LSWaitForMeToExamineTableViewCellID";
static NSString *LSAlreadyApprovedTableViewCellID = @"LSAlreadyApprovedTableViewCellID";

@implementation LSExamineApproveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"查阅审批";
    UIView *headerSelectView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 30)];
    [self.view addSubview:headerSelectView];
    [headerSelectView addSubview:self.waitForMeToExamineButton];
    [headerSelectView addSubview:self.alreadyApprovedButton];
    UIView *headerSelectViewBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 28.5, ScreenWidth, 0.5)];
    headerSelectViewBottomLineView.backgroundColor = COLOR_SEPERATOR;
    [headerSelectView addSubview:headerSelectViewBottomLineView];
    [headerSelectView addSubview:self.headerSelectBottomLineView];
    [self.view addSubview:self.mainContentScrollView];
}

- (void)waitForMeToExamineButtonClick {
    self.waitForMeToExamineButton.selected = true;
    self.alreadyApprovedButton.selected = false;
    [self.mainContentScrollView setContentOffset:CGPointZero animated:true];
}

- (void)alreadyApprovedButtonClick {
    self.waitForMeToExamineButton.selected = false;
    self.alreadyApprovedButton.selected = true;
    [self.mainContentScrollView setContentOffset:CGPointMake(ScreenWidth, 0) animated:true];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.waitForMeToExamineTableView) {// 待我审批的
        LSWaitForMeToExamineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LSWaitForMeToExamineTableViewCellID forIndexPath:indexPath];
        cell.mainDateText = @"2018-12-22";
        cell.mainTitleText = @"待我审批的事由事由事由";
        cell.mainDetailText = @"内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情内容详情";
        return cell;
    } else {// 我已审批的
        LSWaitForMeToExamineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LSAlreadyApprovedTableViewCellID forIndexPath:indexPath];
        cell.mainDateText = @"2018-10-22";
        cell.mainTitleText = @"我已审批的事由事由事由";
        cell.mainDetailText = @"内容详情内容详情内容详情";
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return LSWaitForMeToExamineTableViewCellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.mainContentScrollView) {
        CGFloat mainScrollViewContentOffsetX = scrollView.contentOffset.x;
        [self.headerSelectBottomLineView setContentOffset:CGPointMake((ScreenWidth-mainScrollViewContentOffsetX)/2, 0)];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat mainScrollViewContentOffsetX = scrollView.contentOffset.x;
    NSInteger page = mainScrollViewContentOffsetX/ScreenWidth;
    if (page > 0) {
        self.waitForMeToExamineButton.selected = false;
        self.alreadyApprovedButton.selected = true;
    } else {
        self.waitForMeToExamineButton.selected = true;
        self.alreadyApprovedButton.selected = false;
    }
}

- (UIScrollView *)headerSelectBottomLineView {
    if (!_headerSelectBottomLineView) {
        _headerSelectBottomLineView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30-2, ScreenWidth, 2)];
        _headerSelectBottomLineView.contentSize = CGSizeMake(ScreenWidth/2*3, 2);
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(ScreenWidth/2, 0, ScreenWidth/2, 2)];
        lineView.backgroundColor = NAV_COLOR;
        [_headerSelectBottomLineView addSubview:lineView];
        _headerSelectBottomLineView.contentOffset = CGPointMake(ScreenWidth/2, 0);
    }
    return _headerSelectBottomLineView;
}

- (UIButton *)waitForMeToExamineButton {
    if (!_waitForMeToExamineButton) {
        _waitForMeToExamineButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth/2, 30)];
        _waitForMeToExamineButton.backgroundColor = UIColor.whiteColor;
        [_waitForMeToExamineButton setTitle:@"待我审批的" forState:UIControlStateNormal];
        [_waitForMeToExamineButton setTitleColor:NAV_COLOR forState:UIControlStateSelected];
        [_waitForMeToExamineButton setTitleColor:hexColor(666666) forState:UIControlStateNormal];
        [_waitForMeToExamineButton addTarget:self action:@selector(waitForMeToExamineButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _waitForMeToExamineButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
        _waitForMeToExamineButton.selected = true;
    }
    return _waitForMeToExamineButton;
}

- (UIButton *)alreadyApprovedButton {
    if (!_alreadyApprovedButton) {
        _alreadyApprovedButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth/2, 0, ScreenWidth/2, 30)];
        _alreadyApprovedButton.backgroundColor = UIColor.whiteColor;
        [_alreadyApprovedButton setTitle:@"我已审批的" forState:UIControlStateNormal];
        [_alreadyApprovedButton setTitleColor:NAV_COLOR forState:UIControlStateSelected];
        [_alreadyApprovedButton setTitleColor:hexColor(666666) forState:UIControlStateNormal];
        [_alreadyApprovedButton addTarget:self action:@selector(alreadyApprovedButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _alreadyApprovedButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    }
    return _alreadyApprovedButton;
}

- (UIScrollView *)mainContentScrollView {
    if (!_mainContentScrollView) {
        _mainContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, ScreenWidth, ScreenHeight-SafeAreaTopHeight-30)];
        _mainContentScrollView.contentSize = CGSizeMake(ScreenWidth*2, ScreenHeight-SafeAreaTopHeight-30);
        _mainContentScrollView.pagingEnabled = true;
        [_mainContentScrollView addSubview:self.waitForMeToExamineTableView];
        [_mainContentScrollView addSubview:self.alreadyApprovedTableView];
        _mainContentScrollView.delegate = self;
    }
    return _mainContentScrollView;
}

- (UITableView *)waitForMeToExamineTableView {
    if (!_waitForMeToExamineTableView) {
        _waitForMeToExamineTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight-30)];
        _waitForMeToExamineTableView.separatorInset = UIEdgeInsetsZero;
        _waitForMeToExamineTableView.backgroundColor = UIColor.whiteColor;
        _waitForMeToExamineTableView.tableFooterView = [UIView new];
        _waitForMeToExamineTableView.delegate = self;
        _waitForMeToExamineTableView.dataSource = self;
        [_waitForMeToExamineTableView registerClass:LSWaitForMeToExamineTableViewCell.class forCellReuseIdentifier:LSWaitForMeToExamineTableViewCellID];
    }
    return _waitForMeToExamineTableView;
}

- (UITableView *)alreadyApprovedTableView {
    if (!_alreadyApprovedTableView) {
        _alreadyApprovedTableView = [[UITableView alloc] initWithFrame:CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight-30)];
        _alreadyApprovedTableView.separatorInset = UIEdgeInsetsZero;
        _alreadyApprovedTableView.backgroundColor = UIColor.whiteColor;
        _alreadyApprovedTableView.tableFooterView = [UIView new];
        _alreadyApprovedTableView.delegate = self;
        _alreadyApprovedTableView.dataSource = self;
        [_alreadyApprovedTableView registerClass:LSWaitForMeToExamineTableViewCell.class forCellReuseIdentifier:LSAlreadyApprovedTableViewCellID];
    }
    return _alreadyApprovedTableView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
